
var class2type = {};
var tool = {
  isFunction: function (obj) {
    return typeof obj === "function";
  },
  type: function (obj) {
    if (obj == null) {
      return obj + "";
    }

    // Support: Android <=2.3 only (functionish RegExp)
    return typeof obj === "object" || typeof obj === "function" ?
      class2type[toString.call(obj)] || "object" :
      typeof obj;
  }
}
function isArrayLike(obj) {

  // Support: real iOS 8.2 only (not reproducible in simulator)
  // `in` check used to prevent JIT error (gh-2145)
  // hasOwn isn't used here due to false negatives
  // regarding Nodelist length in IE
  var length = !!obj && "length" in obj && obj.length,
    type = tool.type(obj);

  if (tool.isFunction(obj)) {
    return false;
  }

  return type === "array" || length === 0 ||
    typeof length === "number" && length > 0 && (length - 1) in obj;
}
var each = function (obj, callback) {
  var length, i = 0;
  
  if (isArrayLike(obj)) {
    length = obj.length;
    for (; i < length; i++) {
      if (callback.call(obj[i], i, obj[i]) === false) {
        break;
      }
    }
  } else {
    for (i in obj) {
      if (callback.call(obj[i], i, obj[i]) === false) {
        break;
      }
    }
  }

  return obj;
}
var judgeValueIsLocalImage = function (value) {
  return typeof value === 'string' && (value.indexOf('wxfile://tmp_') === 0 ||  value.indexOf('http://tmp/') === 0)
};

function _dataEach(obj, callback) {
  each(obj, function (k, v) {
    if (typeof v === 'object') {
      _dataEach(v, callback); //递归遍历
    } else if (judgeValueIsLocalImage(v)) {
      
      callback(obj, k, v);
    }
  });
}

function getImages(originData) {
  var arr = [];
  _dataEach(originData, function (obj, k, v) {
    arr.push(v);
  });
  return arr;
}

function assignData(originData, imgUrlArr) {
  var i = 0;
  _dataEach(originData, function (obj, k) {
    obj[k] = imgUrlArr[i];
    i++;
  });
  return originData;
}

module.exports = {
  getImages: getImages,
  assignData: assignData
};